package com.iafme.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iafme.dto.req.CawReqDTO;
import com.iafme.dto.res.CawResDTO;
import com.iafme.model.Caw;
import com.iafme.service.CawService;
import com.systemframework.annotation.OperateAnnotation;
import com.systemframework.common.BaseCommonInterface;
import com.systemframework.enums.BusinessType;
import com.systemframework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author summer
 * @version 1.0
 * @date 2025/2/18 19:52
 */
@RestController
@RequestMapping(value = "/ciFa")
@AllArgsConstructor
public class CiFaController implements BaseCommonInterface<CawReqDTO, CawResDTO> {

    private final CawService cawService;

    @OperateAnnotation(businessType = BusinessType.INSERT,name = "职业认证_ciFa")
    @SaCheckPermission("career:cifa:add")
    @Override
    public Result<String> save(@Valid CawReqDTO cawReqDTO) {
        cawService.saveCaw(cawReqDTO);
        return Result.successResult();
    }

    @OperateAnnotation(businessType = BusinessType.UPDATE,name = "职业认证_ciFa")
    @SaCheckPermission("career:cifa:edit")
    @Override
    public Result<String> update(@Valid CawReqDTO cawReqDTO) {
        cawService.updateCaw(cawReqDTO);
        return Result.successResult();
    }

    @OperateAnnotation(businessType = BusinessType.DELETE,name = "职业认证_ciFa")
    @SaCheckPermission("career:cifa:delete")
    @Override
    public Result<String> del(Integer id) {
        cawService.removeById(id);
        return Result.successResult();
    }

    @Override
    public Result<Page<CawResDTO>> lists(CawReqDTO cawReqDTO) {
        return Result.successResult(cawService.lists(cawReqDTO));
    }

    @Override
    public Result<CawResDTO> findById(Integer id) {
        return Result.successResult(Convert.convert(CawResDTO.class,cawService.getById(id)));
    }

    @OperateAnnotation(businessType = BusinessType.BATCHDELETE,name = "职业认证_ciFa")
    @SaCheckPermission("career:cifa:delete")
    @Override
    public Result<String> batchDel(List<CawResDTO> list) {
        List<Integer> ids = list.stream().map(CawResDTO::getId).collect(Collectors.toList());
        cawService.removeByIds(ids);
        return Result.successResult();
    }
}
